<template>
  <div id="particles">
    <div class="login" @keydown.enter="handleSubmit">
      <div class="login-con">
        <p> 欢迎登录</p>
        <div class="form-con">
          <el-form ref="loginForm" :model="form" status-icon :rules="rules" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="username">
              <el-input v-model="form.username" placeholder="请输入用户名" autocomplete="off" />
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="form.password" type="password" placeholder="请输入密码" autocomplete="off" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        userName: 'admin',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
  },
  methods: {
    submitForm(ref) {
      this.$refs[ref].validate((valid) => {
        if (valid) {
          const userInfo = {
            name: 'hewenke',
            token: '212121212121212121212'
          }
          this.$store.dispatch('user/login', userInfo).then(() => {
            this.$router.push({ path: this.redirect || '/' })
          }).catch(() => {

          })
          // Cookies.set('userInfo', userInfo)
          // this.$store.commit('setUserInfo', userInfo)
          // 设置收缩栏默认为展开
          // this.$store.state.app.sidebar = false
          // 跳转到首页
        }
      })
    }
  }
}
</script>
<style lang="scss">
  .login {
    width: 100%;
    height: 100%;
    background-color: #233554;
    background-size: cover;
    background-position: center;
    position: absolute;
    p{
      line-height: 40px;
      font-size: 20px;
      text-align: left;
    }
    &-con {
      padding:20px;
      padding-right:60px;
      background-color:#fff;
      position: absolute;
      border-radius: 6px;
      left:50%;
      top: 50%;
      transform: translate(-50%,-50%);
      &-header {
        font-size: 16px;
        font-weight: 300;
        text-align: center;
        padding: 30px 0;
      }
      .form-con {
        padding: 10px 0 0;
      }
      .login-tip {
        font-size: 10px;
        text-align: center;
        color: #c3c3c3;
      }
    }
  }
</style>
